<?php
namespace Admin\Controller;
use Common\Controller\AdminbaseController;
class NewsClassController extends AdminbaseController{
	
	function _initialize() {
		parent::_initialize();
	}
	
	function index(){
		$upperId = I("param.upperId", 0);
		$fcateName = I("param.cateName", '无');
		if($upperId==0){
			$result = $this->curl_http(C('news_url').'newsCategory/getNewsCategoryList?token='.$_SESSION["TOKEN"]);
		}else{
			$result = $this->curl_http(C('news_url').'newsCategory/getNewsCategoryList?token='.$_SESSION["TOKEN"].'&upperId='.$upperId);
		}
		$this->assign("fcateName", $fcateName);
		$this->assign("data", $result['ReturnData']['data']);
		$this->display();
	}
	
	function add(){
		$upperId = I("param.upperId", 0);
		$result = $this->curl_http(C('news_url').'newsCategory/findNewsCategoryListByUpperId?token='.$_SESSION["TOKEN"].'&upperId='.$upperId);
		$this->assign("data", $result['ReturnData']['newsCategoryList']);
		$this->display();
	}
	
	function add_post(){
		$name = I("param.cN", "");
		$sI = I("param.sI", 0, "intval");
		if(empty($name)){
			return $this->error("类型名称不能为空！");
		}
		$result = $this->curl_http(C('news_url').'newsCategory/addNewsCategory?token='.$_SESSION["TOKEN"], 'cN='.$name.'&sI='.$sI);
		if($result['Success']){
			$this->success("添加成功！", U("Admin/NewsClass/index"));
		}else{
			return $this->error($result['Message']);
		}
	}
	
	function edit(){
		$this->assign("cateId", I("param.cId", 0));
		$this->assign("cateName", I("param.cN", ""));
		$this->assign("order", I("param.order", ""));
		$this->display();
	}
	
	function edit_post(){
		$name = I("param.cateName", "");
		if(empty($name)){
			return $this->error("类型名称不能为空！");
		}
		$typeId = I("param.cateId", 0);
		$order = I("param.order", 0);
		$result = $this->curl_http(C('news_url').'newsCategory/modifyCategory?token='.$_SESSION["TOKEN"],'cId='.$typeId.'&cN='.$name.'&sI='.$order);
		if($result['Success']){
			$this->success("修改成功！", U("Admin/NewsClass/index"));
		}else{
			return $this->error($result['Message']);
		}
	}
	
	function del(){
		$cId = I("param.cId",0);
		$result = $this->curl_http(C('news_url').'newsCategory/delNewsCategory?token='.$_SESSION["TOKEN"],'categoryIds='.$cId);
		if($result['Success']){
			$this->success("删除成功！", U("Admin/NewsClass/index"));
		}else{
			return $this->error($result['Message']);
		}
	}
	
	public function listorders() {
	if(!empty($_POST['listorders'])){
            foreach($_POST['listorders'] as $key=>$val){
                
                $result = $this->curl_http(C('news_url').'newsCategory/modifyCategory?token='.$_SESSION["TOKEN"].'&cId='.$key.'&sI='.$val);
                if($result['ResultCode'] != '0000'){
                    $this->error("排序更新失败！");
                }
            }
           $this->success("排序更新成功！");
        }
	}

}